<?php
   
/**
 * Mapper for tnotifications
 * 
 * @author Martin Grossmann <snake.aas@gmail.com>
 * @version 1.0
 * @package Mappers
 *
 * @property-read int $idNotification ID of notification
 * @property User $User Notifications to the user
 * @property DateTime $DateInserted Creation date of notification
 * @property string $Text Announcement text. Can be null. 65535 chars max
 * @property boolean $Readed Determines whether the user read the announcement
 * 
 * @entity
 * @table(name="tnotifications", indexes={@index(name="TComments_TPhotos_FK", columns="idPhoto")})
 */     
class Notification {
  
  /**
   * ID of notification
   * 
   * @access private
   * @var int
   * 
   * @Id
   * @Column(name="idNotification", type="integer")
   * @generatedValue
   */
   private $idNotification;
  
  /**
   * Notifications to the user
   * 
   * @access private
   * @var User
   * 
   * @manyToOne(targetEntity="User")
   * @joinColumn(name="idUser", referencedColumnName="idUser")
   */
   private $user;
     
  /**
   * Creation date of notification
   * 
   * @access private
   * @var DateTime
   * 
   * @column(name="DateInserted", type="datetimetz")
   */
   private $dateInserted;
     
  /**
   * Announcement text. Can be null
   * 
   * @access private
   * @var string
   * 
   * @column(name="Text", type="text", nullable=true)
   */
   private $text;
     
  /**
   * Determines whether the user read the announcement
   * 
   * @access private
   * @var boolean
   * 
   * @column(name="Readed", type="boolean")
   */
   private $readed;
     

  public function __get($name) {
    
    switch($name) {      
      case "idNotification": 
        return $this->idNotification;
        break;
      
      case "User": 
        return $this->user;
        break;
    
      case "DateInserted": 
        return $this->dateInserted;
        break;
      
      case "Text": 
        return $this->text;
        break;
      
      case "Readed": 
        return $this->readed;
        break;
      
      default: 
        throw new EntityException(sprintf(T_("Trying to get undefined property")." ", $name));
    }
  }
  
  public function __set($name, $value) {
    
    switch($name) {
      case "User": 
        $this->user = Validations::ValidateObject($value, 'User');
        break; 

      case "Text": 
        $this->text = Validations::validateString($value, 65535, null, true);
        break; 

      case "Readed": 
        $this->readed = Validations::ValidateBoolean($value);
        break; 
      
      default: 
        throw new EntityException(sprintf(T_("Trying to set undefined property")." ", $name));

    }
  }  
  
  public function __construct(User $user = null, $text = null){
    if ($user !== null) $this->User = $user;
    if ($text !== null) $this->Text = $text;
    $this->dateInserted = new DateTime('now');
    $this->readed       = 0;
  }
  
  
  
}